<template>
  <div v-if="scene.refreshFlag">
    <component v-for="(view, key) in scene.views" :is="isViewObject(view)" :key="key" />
  </div>
</template>

<script setup lang="ts">
import type { ContextScene } from "./scene";
import type { BaseModule } from "./module";
import type { BaseView } from "./view";
import { getComponentSymbol } from "./constant";
import ViewSceneDefault from "./ViewSceneDefault.vue";

defineProps<{
  scene: ContextScene<
    Record<string, new (...args: unknown[]) => BaseModule>,
    Record<string, new (...args: unknown[]) => BaseView<NonNullable<unknown>, NonNullable<unknown>>>
  >;
}>();

const isViewObject = computed(() => {
  return (view: true | BaseView<NonNullable<unknown>, NonNullable<unknown>> | undefined) => {
    if (!view || typeof view === "boolean") {
      return ViewSceneDefault;
    }
    return view[getComponentSymbol]();
  };
});
</script>
